require('../../assets/css/index.less');
require('../../assets/css/basic.less');
// 小图标
require('../../assets/fonts/iconfont.css');
require('../../assets/font/iconfont.css');
// 当前页面样式
require('./coursetrain.less');
var weui = require("../../lib/weui/weui.js");
require("../../lib/weui/weui.css");
// 工具函数 utils
const dom = require('../../utils/dom');
const https = require('../../utils/https');
const local = require('../../utils/local');
dom.ready(function() {


    // dom.addEvent(".stopBtn", "click", function() {
    //     dom.getEle(".modal").style.display = "block"
    // })
    // dom.addEvent(".continue", "click", function() {
    //     dom.getEle(".modal").style.display = "none"
    // })
    var num = 0
    var videoUrl = local.get("video")
    randerr()
    dom.getEle(".count").innerHTML = videoUrl.length;
    //标杆思想
    var flag = true;
    dom.addEvent(".stopBtn", "click", function() {
        if (flag) {
            dom.getEle("video").play();
            this.className = "iconfont stopBtn icon-zanting"
        } else {
            dom.getEle("video").pause();
            this.className = "iconfont stopBtn icon-kaishi1"
        };
        flag = !flag;
    })

    //
    dom.addEvent(".back", "click", function() {
        num--;
        if (num == -1) {
            num = videoUrl.length - 1
        }
        randerr()
    })
    dom.addEvent(".next", "click", function() {
        num++;
        if (num == videoUrl.length) {
            num = 0
            weui.alert("课程已结束,即将返回第一个视频");
        }
        randerr()
    })

    //数据渲染
    function randerr() {
        dom.getEle(".countnum").innerHTML = num + 1;
        dom.getEle("video").src = 'http://fitness.h5.itsource.cn:3701' + videoUrl[num].videoUrl;
        dom.getEle(".name").innerHTML = videoUrl[num].title;
        dom.getEle(".stopBtn").className = "iconfont stopBtn icon-kaishi1";
        flag = true
    }

    // 返回
    dom.addEvent(".backBtn", "click", function() {
        1111
        location.href = './course.html'
    })

})